package com.sywl.ytcx.controller.admin;

import com.sywl.ytcx.entity.res.ResponseResult;
import com.sywl.ytcx.service.CommunityActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.YearMonth;

/**
 * @author cjx
 * @description: 社区活跃度控制器
 * @date 2025/8/1 16:07
 */
@RestController
@RequestMapping("/community/activity")
public class CommunityActivityController {

    private final CommunityActivityService activityService;

    @Autowired
    public CommunityActivityController(CommunityActivityService activityService) {
        this.activityService = activityService;
    }

    /**
     * 获取指定日期的日活跃用户数(DAU)
     */
    @GetMapping("/dau")
    public ResponseResult getDAU(
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date) {
        return activityService.getDAU(date);
    }

    /**
     * 获取指定日期范围的周活跃用户数(WAU)
     */
    @GetMapping("/wau")
    public ResponseResult getWAU(
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate start,
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate end) {
        return activityService.getWAU(start, end);
    }

    /**
     * 获取指定年月的月活跃用户数(MAU)
     */
    @GetMapping("/mau")
    public ResponseResult getMAU(
            @RequestParam int year, @RequestParam int month) {
        return activityService.getMAU(YearMonth.of(year, month));
    }

    /**
     * 获取指定日期的新注册用户数
     */
    @GetMapping("/registrations/daily")
    public ResponseResult getDailyRegistrations(
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date) {
        return activityService.countNewRegistrations(date);
    }

    /**
     * 获取指定日期范围的新注册用户数
     */
    @GetMapping("/registrations/range")
    public ResponseResult getRegistrationsInRange(
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate start,
            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate end) {
        return activityService.countNewRegistrationsBetween(start, end);
    }
}
